Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@astrojs/lit] Fix slotted content #5776

Merged
merged 3 commits into from
Jan 6, 2023

Conversation

ba55ie
Copy link
Contributor

@ba55ie ba55ie commented Jan 6, 2023

Changes

I use parse5 to parse the HTML string into a Fragment and then add the missing named slots. This is safer than using regex, but if there's a better parser, don't hesitate to change it.

// Before
<my-element>
    <astro-slot slot="header">
        <h1>Header</h1>
    </astro-slot>

    <astro-slot>
        <p>Content</p>
        <p>Some more content</p>
    </astro-slot>

    <astro-slot slot="footer">
        <small>Legal stuff</small>
        <small>© 2023</small>
    </astro-slot>
</my-element>

// After
<my-element>
    <h1 slot="header">Header</h1>

    <p>Content</p>
    <p>Some more content</p>

    <small slot="footer">Legal stuff</small>
    <small slot="footer">© 2023</small>
</my-element>

Testing

  • Tests have been added for nested slotted HTML and Web Components.
  • The code has been tested in my own projects.

Docs

The docs do not need updating.

@changeset-bot
Copy link

changeset-bot bot commented Jan 6, 2023

🦋 Changeset detected

Latest commit: a1b10b9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: lit Related to Lit (scope) pkg: integration Related to any renderer integration (scope) labels Jan 6, 2023
@matthewp
Copy link
Contributor

matthewp commented Jan 6, 2023

Thanks!

@matthewp matthewp merged commit 6a31433 into withastro:1-legacy Jan 6, 2023
@astrobot-houston astrobot-houston mentioned this pull request Jan 6, 2023
@ba55ie ba55ie deleted the fix/legacy-lit-slots branch January 6, 2023 13:49
@ba55ie ba55ie restored the fix/legacy-lit-slots branch January 7, 2023 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) pkg: lit Related to Lit (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants